package com.xiyu.service.repository.material.info;

import com.xiyu.service.vo.material.warehouse.WarehousePageQueryInput;
import com.xiyu.service.model.material.info.MaterialWarehouse;
import com.xiyu.service.model.material.info.MaterialWarehouseTable;
import org.babyfish.jimmer.spring.repository.JRepository;
import org.babyfish.jimmer.Page;
import org.springframework.util.StringUtils;
import java.util.Optional;

public interface MaterialWarehouseRepository extends JRepository<MaterialWarehouse, Long> {
    MaterialWarehouseTable materialWarehouseTable = MaterialWarehouseTable.$;

    default Page<MaterialWarehouse> pageQuery(WarehousePageQueryInput inputVO){
        return sql().createQuery(materialWarehouseTable)
                .whereIf(StringUtils.hasText(inputVO.getWarehouseName()), () -> materialWarehouseTable.warehouseName().like(inputVO.getWarehouseName()))
                .orderBy(materialWarehouseTable.id().desc())
                .select(materialWarehouseTable)
                .fetchPage(inputVO.getPageNo() - 1, inputVO.getPageSize());
    }

    Optional<MaterialWarehouse> findFirstByWarehouseName(String warehouseName);


}